package main

import(
	"fmt"
    "sort"
	"util/array"
)

type SortList[K array.KEYS, V string|int|int8|int16|int32|int64|float32|float64] struct {
    Desc bool
    array.List[K,V]
}
func (l *SortList[K,V])Less(i, j int) bool {
    if l.Desc { return array.GetValue[K,V](l, i) > array.GetValue[K,V](l, j) }
    return array.GetValue[K,V](l, i) < array.GetValue[K,V](l, j)
}
func (l *SortList[K,V])New() array.Arrays[K,V] { return &SortList[K,V]{} }

type TestList[K array.KEYS, V array.VALUES] struct {
    array.List[K,V]
}
func (l *TestList[K,V])New() array.Arrays[K,V] { return &TestList[K,V]{} }
func (l *TestList[K,V])Less(i, j int) bool {
    var (
        t1, t2 any
    )
    t1, t2 = array.GetValue[K,V](l, i), array.GetValue[K,V](l, j)

    return t1.(*TestList[K,V]) > t2.(*TestList[K,V])
}

type OrderList[K array.KEYS, V array.VALUES] struct {
    Order int
    array.List[K,V]
}
func (l *OrderList[K,V])New() array.Arrays[K,V] { return &OrderList[K,V]{} }
func (l *OrderList[K,V])Less(i, j int) bool {
    var (
        o1, o2 any
    )
    o1, o2 = array.GetValue[K,V](l, i), array.GetValue[K,V](l, j)
    return o1.(*OrderList[K,V]).Order > o2.(*OrderList[K,V]).Order
}

func main() {
    list := &OrderList[string,any]{}
    list.Init(map[string]any{"list4": &OrderList[string,any]{}, "list1": &OrderList[string,any]{}, "list2": &OrderList[string,any]{}, "list3": &OrderList[string,any]{}})
    list1, list2, list3, list4 := array.Get[string,any](list, "list1").(*OrderList[string,any]), array.Get[string,any](list, "list2").(*OrderList[string,any]), array.Get[string,any](list, "list3").(*OrderList[string,any]), array.Get[string,any](list, "list4").(*OrderList[string,any])
    list1.Order, list2.Order, list3.Order, list4.Order = 1234, 546, 57567, 7657
    fmt.Println("OrderList Sort Start：", list)
    sort.Sort(list)
    fmt.Println("OrderList Sort End：", list)
}